package com.itheima.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.entity.Setmeal;
import com.itheima.entity.SetmealCheckgroup;
import com.itheima.service.SetmealCheckGroupService;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 一抹星辰
 * @date 2021年12月13日 13:53
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    /**
     * 检查组分页查询请求：页码+条数+查询条件
     *检查组分页查询响应： 总条数+展示数据的集合
     * @param currentPage 当前页面页号
     * @param pageSize    当前页面条数
     * @param queryString        按条件查询
     */
    @Autowired
    private SetmealCheckGroupService setmealCheckGroupService;
    @Autowired
    private SetmealService setmealService;
    @GetMapping("/page")
    public R<Page<Setmeal>> page(int currentPage, int pageSize, String queryString) {
        return null;
    }

    @PostMapping("/add")
    public R<String> add(@RequestBody Setmeal setmeal) {
        return null;
    }

    @DeleteMapping("/delete")
    public R<String> delete(int id){
        LambdaQueryWrapper<SetmealCheckgroup> setmealCheckGroupLambdaQueryWrapper = new LambdaQueryWrapper<>();
        setmealCheckGroupLambdaQueryWrapper.eq(SetmealCheckgroup::getSetmealId,id);
        //删除关联条件
        setmealCheckGroupService.remove(setmealCheckGroupLambdaQueryWrapper);
        //对setmeal的删除
        setmealService.removeById(id);
        return R.success("删除成功");
    }

    @PutMapping("/update")
    public R<String> update(@RequestBody Setmeal setmeal){
        setmealService.updateById(setmeal);
        return R.success("修改成功");
    }
}
